#include<stdio.h>
#include<sys/wait.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/types.h>
#include<stdlib.h>
#include<string.h>

int main()
{
    int fd[2];
    pipe(fd);
    pid_t pid = fork();
    if(pid == 0)
    {
        close(fd[1]);
            char buf[1024] = {0};
            int n = read(fd[0], buf, sizeof(buf));
            if(n > 0)
            {
                printf("Child received: %s\n", buf);
            }
            close(fd[0]);
    }
    else
    {
        close(fd[0]);
        char msg[] = "hello from parent";
        write(fd[1], msg, strlen(msg));
        close(fd[1]);
        wait(NULL);
    }
    return 0;
}
